#define _CRT_SECURE_NO_WARNINGS 1

#include <iostream>
#include <vector>
#include <queue>
#include <climits>
using namespace std;



int main() {
    int n;
    cin >> n;
    vector<long long> v(n);
    long long min = LONG_MAX;
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
        if (v[i] < min)
            min = v[i];
    }
    priority_queue<long long> q;
    for (int i = 0; i < n; ++i)
        q.push(v[i]);

    int ans = 0;
    while (q.top() > 2 * min) {
        int max = q.top();
        q.pop();
        q.push(max / 2);
        if (max % 2 == 0)
            q.push(max / 2);
        else
            q.push(max / 2 + 1);
        ++ans;
    }
    cout << ans << endl;
    return 0;
}



int gcd(int count1, int count2) {
    if (count1 == 1 || count2 == 1)
        return 1;
    if (count1 == 0)
        return count2;
    if (count2 == 0)
        return count1;
    if (count1 == count2)
        return count1;

    if (count1 > count2)
        return gcd(count2, count1 % count2);
    else
        return gcd(count1, count2 % count1);
}
int main() {
    int T;
    cin >> T;
    while (T--) {
        int n;
        cin >> n;
        vector<int> v(n + 1);
        for (int i = 1; i <= n; ++i) {
            cin >> v[i];
        }

        int leave = 1;
        while (leave < n) {
            int right = n / leave;
            int left = (n / (leave + 1)) + 1;
            leave++;
            if (left >= right)
                continue;
            int minGcd = INT_MAX;
            int tmp = v[left];
            for (int i = left; i < right; ++i) {
                tmp = gcd(tmp, v[i + 1]);
                if (tmp < minGcd)
                    minGcd = tmp;
            }
            for (int i = left; i <= right; ++i) {
                v[i] = minGcd;
            }
        }

        int ans = 0;
        for (int i = 1; i <= n; ++i) {
            ans += v[i];
        }
        cout << ans << endl;
    }
    return 0;
}